﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for CategoryBusiness
/// </summary>
public class CategoryBusiness
{
    CategoryData cate = new CategoryData();
	public CategoryBusiness()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public bool add(CategoriesEntities item)
    {
        return cate.add(item);
    }
    public bool edit(CategoriesEntities item)
    {
        return cate.edit(item);
    }
    public bool delete(int id)
    {
        return cate.delete(id);
    }

    public CategoriesEntities getItem(int id)
    {
        CategoriesEntities item = null;
        if (id > 0)
        {
            DataTable dt = cate.getCategory(id);
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
                item = new CategoriesEntities();
                item._id = int.Parse(row["id"].ToString().Trim());
                item._name = row["name"].ToString();
                item._priority = int.Parse(row["priority"].ToString().Trim());
                item._display = row["display"].ToString();
            }
        }
        return item;
    }

    public System.Collections.ArrayList getCategory()
    {
        System.Collections.ArrayList items = new System.Collections.ArrayList();
        DataTable dt = cate.getCategory(0);
        if (dt != null)
        {
            CategoriesEntities item = null;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                item = new CategoriesEntities();
                item._id = int.Parse(row["id"].ToString().Trim());
                item._name = row["name"].ToString();
                item._priority = int.Parse(row["priority"].ToString().Trim());
                item._display = row["display"].ToString();
                items.Add(item);
                item = null;
            }
        }
        return items;
    }

    public System.Collections.ArrayList getCategoryView()
    {
        System.Collections.ArrayList items = new System.Collections.ArrayList();
        System.Collections.ArrayList tmp = this.getCategory();
        if (tmp != null)
        {
            CategoriesEntities item = null;
            for (int i = 0; i < tmp.Count; i++)
            {
                item = (CategoriesEntities)tmp[i];
                if (item._display.Trim().Equals("True") || item._display.Trim().Equals("1"))
                {
                    items.Add(item);
                }
                item = null;
            }
        }
        return items;
    }
}
